package com.jy.modules.cims.interact;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jy.modules.cims.common.sysUtils.DateTimeUtils;
import com.jy.modules.cims.data.common.dto.LoggingEventDTO;
import com.jy.modules.cims.data.dao.LoggingDao;

/**
 * @classname LoggingEventService
 * @description LoggingEvent服务实现类
 * @author shengzhoutao
 */
@Service("com.jy.modules.cims.interact.LoggingService")
public class LoggingService {

	@Autowired
	private LoggingDao loggingDao;

	/**
	 * @Description 删除指定日期的若干天数以前(包含指定日期)的LoggingEvent信息.
	 * @param date
	 *            指定日期参数
	 * @param days
	 *            向前历史的日期数
	 * @throws Exception
	 * @author shengzhoutao
	 */
	public void deleteInvalidLoggingEvent(Date date, int days) throws Exception {
		Date historyDate = DateTimeUtils.addDays(date, -days);

		Map<String, Object> paramMap = new HashMap<String, Object>();
		LoggingEventDTO loggingEvent = new LoggingEventDTO();
		loggingEvent.setTimestmp(historyDate.getTime());
		paramMap.put("dto", loggingEvent);

		loggingDao.deleteHistoryLoggingEventException(paramMap);
		
		loggingDao.deleteHistoryLoggingEventProperty(paramMap);
		
		loggingDao.deleteHistoryLoggingEvent(paramMap);

		paramMap = null;
		loggingEvent = null;
	}

}
